package com.lagou.edu.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.UUID;

/**
 * @author 黄子濠
 * @date 2020/7/12 20:23
 */
@Controller
@RequestMapping("/sys")
public class SysController {

    @Autowired
    private HttpServletRequest httpServletRequest;
    @RequestMapping("/login")
    public String login(String username, String password,ModelMap map) throws Exception {
        ModelAndView mv = new ModelAndView();
        if ("admin".equals(username)&& "admin".equals(password)){
            httpServletRequest.getSession().setAttribute("token", "admin"+UUID.randomUUID());
            return "redirect:/resume/list";
        }
        return "login";
    }

    @RequestMapping("/logout")
    public String login(ModelMap map) throws Exception {
        httpServletRequest.getSession().removeAttribute("token");
        return "login";
    }
}
